package com.randi.system.service.impl.sysLog;

import com.github.pagehelper.PageInfo;
import com.randi.common.constant.CacheConstants;
import com.randi.system.domain.entity.sysLog.SysLogLogin;
import com.randi.system.domain.params.sysLog.SysLogLoginParam;
import com.randi.system.mapper.sysLog.SysLogLoginMapper;
import com.randi.system.service.sysLog.ISysLogLoginService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * @author ziye
 */
@Service
@CacheConfig(cacheNames = CacheConstants.SYS_LOG_LOGIN)
public class SysLogLoginServiceImpl implements ISysLogLoginService {

    @Resource
    private SysLogLoginMapper sysLogLoginMapper;

    /**
     * 分页查询业务列表
     *
     * @param sysLogLoginParam 检索参数
     * @return 业务集合
     */
    @Override
    @Cacheable(keyGenerator = "baseKeyGenerator", unless = "#result == null")
    public PageInfo<SysLogLogin> selectPageList(SysLogLoginParam sysLogLoginParam) {
        return new PageInfo<>(sysLogLoginMapper.selectSysLogLoginList(sysLogLoginParam));
    }

    /**
     * 查看详情
     *
     * @return 业务集合
     */
    @Override
    @Cacheable(key = "#infoId", unless = "#result == null")
    public SysLogLogin selectSysLogLoginById(Long infoId) {
        return sysLogLoginMapper.selectSysLogLoginById(infoId);
    }

    /**
     * 插入数据
     *
     * @param sysLogLogin sysLoginInfo
     * @return 结果
     */
    @Override
    @CacheEvict(allEntries = true, beforeInvocation = true)
    public int insertSysLogLogin(SysLogLogin sysLogLogin) {
        return sysLogLoginMapper.insert(sysLogLogin);
    }

    /**
     * 更新数据
     *
     * @param sysLogLogin SysLogLogin
     * @return 结果
     */
    @Override
    @CacheEvict(allEntries = true, beforeInvocation = true)
    public int updateSysLogLogin(SysLogLogin sysLogLogin) {
        return sysLogLoginMapper.updateById(sysLogLogin);
    }

    /**
     * 批量删除数据
     *
     * @param infoIds infoIds
     * @return status
     */
    @Override
    @CacheEvict(allEntries = true, beforeInvocation = true)
    public int deleteBatchSysLogLogin(List<Long> infoIds) {
        return sysLogLoginMapper.deleteBatchIds(infoIds);
    }

}
